﻿using System;
using System.IO;
using System.Collections.Generic;
using MathNet.Numerics.LinearAlgebra.Double;
using MathNet.Numerics.LinearAlgebra.Generic;
using innovations.ml.core.models;

namespace innovations.ml.data
{
    public abstract class Loader
    {
        public abstract Model Load(int numberOfRecords = -1);
        public static double[,] LoadFile(string path, int numberOfRecords)
        {            
            if (string.IsNullOrEmpty(path))
                throw new ArgumentNullException("Path property must not be null.");
            string[] lines = File.ReadAllLines(path);
            int columnCount = lines[0].Split(',').Length;

            if (numberOfRecords == -1)
                numberOfRecords = lines.Length;
            double[,] dataArray = new double[numberOfRecords, columnCount];
            // fill arrays in #columnsArray with data
            for (int i = 0; i < numberOfRecords; i++)
            {
                for (int j = 0; j < columnCount; j++)
                {
                    string[] line = lines[i].Split(',');
                    dataArray[i, j] = Convert.ToDouble(line[j]);
                }
            }
            return dataArray;
        }
     }
}
